package com.grouplay.dao;

import com.grouplay.entity.Group;
import com.grouplay.entity.Invitation;
import com.grouplay.entity.UserGroup;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Repository;

@Repository("userGroupDao")
public interface IUserGroupDao {

    @Select("select count(*) + 1 from `user_group` where gid = #{groupId}")
    Integer findNumberOfMembersByGroupId(Integer groupId);

    @Insert("insert into user_group (uid, gid) values (#{targetUid}, #{groupId})")
    void joinInGroupByInvitation(Invitation invitation);

    @Select("select count(*) from `user_group` where gid = #{id} and uid = #{leaderId}")
    Integer userIsInGroup(Group group);

    @Update("update user_Group set isPay = 1 where uid = #{uid} and gid = #{gid}")
    void updateIsPay(UserGroup userGroup);
}
